﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class SimplaAdminDemoForm : ItemFormTemplate
    {
        public SimplaAdminDemoForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {

        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            List<SingleAccordionNode> nodeList = new List<SingleAccordionNode>();
            {
                SingleAccordionContentNode singleAccordionContentNode1 = new HML.SingleAccordionContentNode() { Text = "Dashboard", TBMargin = new TBMargin(0, 10), TextLRMargin = new LRMargin(0, 10), MouseAnimationEnabled = SingleAccordionMouseAnimationEnableds.True, LRAnimationDistance = 10 };
                singleAccordionContentNode1.StyleAppearance.Normal.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionContentNode1.StyleAppearance.Enter.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionContentNode1.StyleAppearance.Selected.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionContentNode1.StyleAppearance.Normal.TextColor = Color.FromArgb(255, 255, 255);
                singleAccordionContentNode1.StyleAppearance.Enter.TextColor = Color.FromArgb(255, 255, 255);
                singleAccordionContentNode1.StyleAppearance.Selected.TextColor = Color.FromArgb(255, 255, 255);
                nodeList.Add(singleAccordionContentNode1);

                SingleAccordionCategoryNode singleAccordionCategoryNode0 = new HML.SingleAccordionCategoryNode() { Expand = true, Text = "Articles", TBMargin = new TBMargin(0, 10), TextLRMargin = new LRMargin(0, 10), MouseAnimationEnabled = SingleAccordionMouseAnimationEnableds.True, LRAnimationDistance = 10 };
                singleAccordionCategoryNode0.StyleAppearance.Normal.BackColor = Color.FromArgb(255, 255, 255);
                singleAccordionCategoryNode0.StyleAppearance.Enter.BackColor = Color.FromArgb(255, 255, 255);
                singleAccordionCategoryNode0.StyleAppearance.Normal.TextColor = Color.FromArgb(51, 51, 51);
                singleAccordionCategoryNode0.StyleAppearance.Enter.TextColor = Color.FromArgb(51, 51, 51);
                nodeList.Add(singleAccordionCategoryNode0);
                singleAccordionCategoryNode0.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Write a new Article", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode0.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Manage Articles", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode0.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Manage Comments", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode0.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Manage Categories", TextLRMargin = new LRMargin(0, 10) });

                SingleAccordionCategoryNode singleAccordionCategoryNode1 = new HML.SingleAccordionCategoryNode() { Text = "Pages", TBMargin = new TBMargin(0, 10), TextLRMargin = new LRMargin(0, 10), MouseAnimationEnabled = SingleAccordionMouseAnimationEnableds.True, LRAnimationDistance = 10 };
                singleAccordionCategoryNode1.StyleAppearance.Normal.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionCategoryNode1.StyleAppearance.Enter.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionCategoryNode1.StyleAppearance.Normal.TextColor = Color.FromArgb(255, 255, 255);
                singleAccordionCategoryNode1.StyleAppearance.Enter.TextColor = Color.FromArgb(255, 255, 255);
                nodeList.Add(singleAccordionCategoryNode1);
                singleAccordionCategoryNode1.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Create a new Page", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode1.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Manage Pages", TextLRMargin = new LRMargin(0, 10) });

                SingleAccordionCategoryNode singleAccordionCategoryNode2 = new HML.SingleAccordionCategoryNode() { Text = "Image Gallery", TBMargin = new TBMargin(0, 10), TextLRMargin = new LRMargin(0, 10), MouseAnimationEnabled = SingleAccordionMouseAnimationEnableds.True, LRAnimationDistance = 10 };
                singleAccordionCategoryNode2.StyleAppearance.Normal.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionCategoryNode2.StyleAppearance.Enter.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionCategoryNode2.StyleAppearance.Normal.TextColor = Color.FromArgb(255, 255, 255);
                singleAccordionCategoryNode2.StyleAppearance.Enter.TextColor = Color.FromArgb(255, 255, 255);
                nodeList.Add(singleAccordionCategoryNode2);
                singleAccordionCategoryNode2.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Upload Images", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode2.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Manage Galleries", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode2.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Manage Albums", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode2.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Gallery Settings", TextLRMargin = new LRMargin(0, 10) });

                SingleAccordionCategoryNode singleAccordionCategoryNode3 = new HML.SingleAccordionCategoryNode() { Text = "Events Calendar", TBMargin = new TBMargin(0, 10), TextLRMargin = new LRMargin(0, 10), MouseAnimationEnabled = SingleAccordionMouseAnimationEnableds.True, LRAnimationDistance = 10 };
                singleAccordionCategoryNode3.StyleAppearance.Normal.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionCategoryNode3.StyleAppearance.Enter.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionCategoryNode3.StyleAppearance.Normal.TextColor = Color.FromArgb(255, 255, 255);
                singleAccordionCategoryNode3.StyleAppearance.Enter.TextColor = Color.FromArgb(255, 255, 255);
                nodeList.Add(singleAccordionCategoryNode3);
                singleAccordionCategoryNode3.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Calendar Overview", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode3.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Add a new Event", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode3.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Calendar Settings", TextLRMargin = new LRMargin(0, 10) });

                SingleAccordionCategoryNode singleAccordionCategoryNode4 = new HML.SingleAccordionCategoryNode() { Text = "Settings", TBMargin = new TBMargin(0, 10), TextLRMargin = new LRMargin(0, 10), MouseAnimationEnabled = SingleAccordionMouseAnimationEnableds.True, LRAnimationDistance = 10 };
                singleAccordionCategoryNode4.StyleAppearance.Normal.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionCategoryNode4.StyleAppearance.Enter.BackColor = Color.FromArgb(121, 185, 0);
                singleAccordionCategoryNode4.StyleAppearance.Normal.TextColor = Color.FromArgb(255, 255, 255);
                singleAccordionCategoryNode4.StyleAppearance.Enter.TextColor = Color.FromArgb(255, 255, 255);
                nodeList.Add(singleAccordionCategoryNode4);
                singleAccordionCategoryNode4.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "General", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode4.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Design", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode4.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Your Profile", TextLRMargin = new LRMargin(0, 10) });
                singleAccordionCategoryNode4.Childrens.Add(new HML.SingleAccordionContentNode() { Text = "Users and Permissions", TextLRMargin = new LRMargin(0, 10) });

            }
            this.demo_control_panel.Width = (int)Math.Ceiling(225 * this.demo_control.ScaleDpi);
            this.demo_content_panel.Location = new Point(this.demo_control_panel.Width, 0);
            this.demo_content_panel.Size = new Size(this.demo_content_panel.Parent.Size.Width - this.demo_control_panel.Width, this.demo_content_panel.Parent.Size.Height);
            this.demo_control.Alignment = SingleAccordionAlignments.Right;
            this.demo_control.BackColor = Color.Transparent;
            this.demo_control.BorderVisible = false;
            this.demo_control.Font = new Font("Bahnschrift SemiBold", 9.5F);
            this.demo_control.ContentNodeStyle.MouseAnimationAllTimer = 150;
            this.demo_control.ContentNodeStyle.LRAnimationDistance = 0;
            this.demo_control.StyleAppearance.ContentNode.Enter.BackColor = Color.Transparent;
            this.demo_control.StyleAppearance.ContentNode.Normal.BackColor = Color.Transparent;
            this.demo_control.StyleAppearance.ContentNode.Selected.BackColor = Color.Transparent;
            this.demo_control.StyleAppearance.ContentNode.Normal.TextColor = Color.White;
            this.demo_control.StyleAppearance.ContentNode.Normal.TextColor = Color.Transparent;
            this.demo_control.StyleAppearance.ContentNode.Selected.TextColor = Color.White;
            this.demo_control.StyleAppearance.ScrollBar.Normal.TrackBackColor = Color.Transparent;
            this.demo_control.StyleAppearance.ScrollBar.Enter.TrackBackColor = Color.Transparent;
            this.demo_control.StyleAppearance.ScrollBar.Normal.ThumbBackColor = Color.Transparent;
            this.demo_control.StyleAppearance.ScrollBar.Enter.ThumbBackColor = Color.Transparent;
            this.demo_control.Nodes.Clear();
            this.demo_control.Nodes.AddRange(nodeList.ToArray());
            this.demo_control.SelectedNode = ((SingleAccordionCategoryNode)this.demo_control.Nodes[1]).Childrens[1];
            this.demo_control.NodeDrawBefore += new HML.SingleAccordion.SingleAccordionNodeDrawBeforeEventHandler(this.Demo_control_NodeDrawBefore);
            this.demo_control.NodeClick += this.Demo_control_NodeClick;

            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn());
            dt.Columns.Add(new DataColumn());
            dt.Columns.Add(new DataColumn());
            dt.Columns.Add(new DataColumn());

            for (int i = 0; i < 5; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = "Lorem ipsum dolor";
                dr[1] = "Sit amet";
                dr[2] = "Consectetur adipiscing";
                dr[3] = "Donec tortor diam";
                dt.Rows.Add(dr);
            }

            this.dataGridView1.DataSource = dt;

            DropDownListPlusItemCollection ddlpc = new DropDownListPlusItemCollection() {
            new DropDownListPlusItem(){ Text="Choose an action" },
            new DropDownListPlusItem(){ Text="Edit" },
            new DropDownListPlusItem(){ Text="Delete" },
            };
            this.dropDownListPlus1.BindItemsSource(ddlpc, ddlpc[0]);

            this.paginationBar1.StyleAppearance.FLButton.Normal.BackColor = Color.Transparent;
            this.paginationBar1.StyleAppearance.PNButton.Normal.BackColor = Color.Transparent;
            this.paginationBar1.StyleAppearance.GButton.Normal.BackColor = Color.Transparent;
            this.paginationBar1.SetPagination(5, 200, 10, 6);


        }

        private void Demo_control_NodeDrawBefore(object sender, SingleAccordionNodeDrawBeforeEventArgs e)
        {
            SingleAccordion sa = (SingleAccordion)sender;
            if (e.Node is SingleAccordionContentNode && e.Node.Parent != null)
            {
                if (sa.SelectedNode == e.Node)
                {
                    e.TextBrush.Color = Color.FromArgb(255, 255, 255);
                }
                else if (e.Node.MouseAnimationStatus == SingleAccordionNodeMouseAnimationStatuss.MouseEnter)
                {
                    e.TextBrush.Color = Color.FromArgb(255, 255, 255);
                }
                else if (e.Node.MouseAnimationStatus == SingleAccordionNodeMouseAnimationStatuss.MouseEntering)
                {
                    int rgb = Math.Max(128, Math.Min(byte.MaxValue, 175 + (int)Math.Ceiling((255 - 175) * AnimationHelper.EaseOut(e.Node.MouseAnimationUsedTime, e.Node.GetMouseAnimationAllTime(), 0.5))));
                    e.TextBrush.Color = Color.FromArgb(rgb, rgb, rgb);
                }
                else if (e.Node.MouseAnimationStatus == SingleAccordionNodeMouseAnimationStatuss.MouseLeaveing)
                {
                    int rgb = Math.Max(128, Math.Min(byte.MaxValue, 175 + (int)Math.Ceiling((255 - 175) * (1 - AnimationHelper.EaseOut(e.Node.MouseAnimationUsedTime, e.Node.GetMouseAnimationAllTime(), 0.5)))));
                    e.TextBrush.Color = Color.FromArgb(rgb, rgb, rgb);
                }
                else if (e.Node.MouseAnimationStatus == SingleAccordionNodeMouseAnimationStatuss.MouseLeave)
                {
                    e.TextBrush.Color = Color.FromArgb(170, 170, 170);
                }
            }

            Graphics g = e.Graphics;
            SmoothingMode sm = g.SmoothingMode;

            if ((e.Node is SingleAccordionContentNode && e.Node.Parent == null) || (e.Node is SingleAccordionCategoryNode))
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.FillPath(e.BackBrush, HML.ControlHelper.AdjustCircularPath(e.Bounds_C, 3, 0, 0, 3));
                g.SmoothingMode = sm;

                g.DrawString(e.Node.Text, sa.Font, e.TextBrush, e.TextBounds_C, StringFormat.GenericTypographic);

                e.Cancel = true;
            }
            if (e.Node is SingleAccordionContentNode && sa.SelectedNode == e.Node)
            {
                int center = e.Bounds_C.Y + e.Bounds_C.Height / 2;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                Color back_color_tmp = e.BackBrush.Color;
                e.BackBrush.Color = Color.FromArgb(255, 255, 255);
                g.FillPolygon(e.BackBrush, new PointF[] { new PointF(e.Bounds_C.Right, center - 5), new PointF(e.Bounds_C.Right, center + 5), new PointF(e.Bounds_C.Right - 6, center), });
                e.BackBrush.Color = back_color_tmp;
            }

            g.SmoothingMode = sm;
        }

        private void Demo_control_NodeClick(object sender, SingleAccordionNodeEventArgs e)
        {
            if (e.Node is SingleAccordionContentNode && e.Node.Parent == null)
            {
                SingleAccordion sa = (SingleAccordion)sender;
                SingleAccordionCategoryNode[] category_node_arr = sa.FindExpand();
                if (category_node_arr.Length > 0)
                {
                    sa.ExpandCollapse(category_node_arr[0], false, true);
                }
            }
        }

        #endregion

    }
}
